From a22b5c2c97b930a14a141bc759c3375337ae4bef Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sat, 8 Mar 2008 20:00:53 +0000 Subject: [PATCH] dmtlog: Limit strings to 254 characters, until we are know, how to handle them correctly. --- gpsbabel/dmtlog.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/gpsbabel/dmtlog.c b/gpsbabel/dmtlog.c index 502db35ff..0d11cf2ca 100644 --- a/gpsbabel/dmtlog.c +++ b/gpsbabel/dmtlog.c @@ -324,6 +324,26 @@ read_str(gbfile *f) return res; } +static void +write_str(const char *str, gbfile *f) +{ + if (str && *str) { + int len = strlen(str); + if (len > 0xfe) { +#if 0 + if (len > 0x7fff) len = 0x7fff; + gbfputc((unsigned char) 0xff, f); + gbfputint16(len, f); +#else + len = 0xfe; + gbfputc(len, f); +#endif + } + else gbfputc(len, f); + gbfwrite(str, len, 1, f); + } + else gbfputc(0, f); +} static int read_datum(gbfile *f) @@ -670,18 +690,18 @@ write_header(const route_head *trk) queue *curr, *prev; QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++; } - gbfputpstr(trk && trk->rte_name && *trk->rte_name ? trk->rte_name : "Name", fout); + write_str(trk && trk->rte_name && *trk->rte_name ? trk->rte_name : "Name", fout); xasprintf(&cout, "%d trackpoints and %d waypoints", count, waypt_count()); - gbfputpstr(cout, fout); + write_str(cout, fout); xfree(cout); for (i = 3; i <= 8; i++) gbfputc(ZERO, fout); - gbfputpstr("GPSBabel", fout); + write_str("GPSBabel", fout); gbfputint32(count, fout); if (count > 0) { - gbfputpstr("WGS84", fout); - gbfputpstr("WGS84", fout); + write_str("WGS84", fout); + write_str("WGS84", fout); } } @@ -721,8 +741,8 @@ wpt_cb(const waypoint *wpt) names = 1; if (wpt->description && *wpt->description) names = 2; gbfputint32(names, fout); - if (names > 1) gbfputpstr(wpt->description, fout); - gbfputpstr(wpt->shortname && *wpt->shortname ? wpt->shortname : "Name", fout); + if (names > 1) write_str(wpt->description, fout); + write_str(wpt->shortname && *wpt->shortname ? wpt->shortname : "Name", fout); } static void @@ -746,8 +766,8 @@ dmtlog_write(void) write_header(NULL); gbfputint32(waypt_count(), fout); if (waypt_count() > 0) { - gbfputpstr("WGS84", fout); - gbfputpstr("WGS84", fout); + write_str("WGS84", fout); + write_str("WGS84", fout); waypt_disp_all(wpt_cb); } } -- 2.30.2